package com.yaozheng.vocationaltraining.dialog.service;

import android.content.DialogInterface;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.dialog.BaseDialog;
import com.yaozheng.vocationaltraining.service.BaseService;
import com.yaozheng.vocationaltraining.view.paper.CarryOutAnAssignmentAskView;
import com.yaozheng.vocationaltraining.view.paper.CarryOutAnAssignmentAskView_;

/**
 */
public class CancelAskDialog extends BaseDialog implements DialogInterface.OnKeyListener {
    CarryOutAnAssignmentAskView carryOutAnAssignmentAskView;
    String runMethod;
    boolean isCLickBackDissDialog = true;
    private BaseService baseService;

    public CancelAskDialog(BaseService baseService) {

        super(baseService, R.style.baseDialogStyleTheme, true, Gravity.CENTER);
        this.baseService = baseService;
    }

    @Override
    public void setContentView() {
        carryOutAnAssignmentAskView = CarryOutAnAssignmentAskView_.build(getContext());
        carryOutAnAssignmentAskView.setBaseDialogEventProcess(this);

        setContentView(carryOutAnAssignmentAskView);
    }

    @Override
    public void initBaseDialog() {
        Window window = getWindow();
        WindowManager.LayoutParams layoutpara = window
                .getAttributes();
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        layoutpara.gravity = Gravity.CENTER;
        if (isCover) {


            layoutpara.dimAmount = (float) (getContext().getResources().getInteger(R.integer.baseDialogdimAmount) / 10.0); // 添加背景遮盖
        } else {
            layoutpara.dimAmount = 0f;
        }
        layoutpara.width = WindowManager.LayoutParams.FILL_PARENT;
        setAttributes(window, layoutpara);
        setCanceledOnTouchOutside(false);
        setOnKeyListener(this);
    }

    public void setContentValue(String value) {
        carryOutAnAssignmentAskView.setContentValue(value);
    }

    public void setTitileValue(String titileValue) {
        carryOutAnAssignmentAskView.setTitleValue(titileValue);
    }


    public void setRunMethod(String runMethod) {
        this.runMethod = runMethod;
    }

    /**
     * 确定
     */
    public void determine() {
        cancel();
        if (runMethod == null) {
            runMethod = "cancelAskDialogDetermine";
        }
        baseService.reflexRunClick(runMethod);
    }

    @Override
    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && isCLickBackDissDialog) {
            return true;
        } else {
            return false;
        }

    }
}
